<template>
    <div style="margin: 10px 0">
      <van-cell-group >
        <van-cell title="停车场名称"  :value="rePayInfo.parkName" />
        <van-cell title="停车场位置" :value="rePayInfo.parkAdr"  />
        <van-cell title="车牌号" :value="rePayInfo.carno" />
        <van-cell title="预约时间" :value="rePayInfo.satrTime"  />
      </van-cell-group>
      <div style='margin:30px auto;font-size:2rem'>
        <p style='text-align: center'>
            <b>￥ {{rePayInfo.fee}}</b>
        </p>
      </div>
      <div style='position: fixed;bottom: 0px;width: 100%'>
        <van-button size="large" style="background-image: linear-gradient(-90deg, #508DFF 0%, #30AFF7 100%);color: white" @click='PayFee'>支付</van-button>
      </div>
    </div>
</template>

<script>
    export default {
      name: "reserverPay",
      data() {
          return {
            rePayInfo:{}
          }
      },
      created(){},
      mounted() {
        this.rePayInfo = this.$route.params.rePayinfo
      },
      methods:{
            // ---调起支付
        PayFee() {
              //  微信环境
              if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                  document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                }else if (document.attachEvent){
                  document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                  document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                }
              }else{
                this.onBridgeReady();
              }
            },
        //  请求支付
        onBridgeReady(){
          WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
              "appId": this.rePayInfo.appId,     //公众号名称，由商户传入
              "timeStamp":String(this.rePayInfo.timeStamp),         //时间戳，自1970年以来的秒数
              "nonceStr": this.rePayInfo.nonceStr, //随机串
              "package": "prepay_id="+this.rePayInfo.prepay_id,
              "signType":"MD5",         //微信签名方式：
              "paySign": this.rePayInfo.sign //微信签名
            },
            function(res){
              if(res.err_msg == "get_brand_wcpay_request:ok" ){
                // 使用以上方式判断前端返回,微信团队郑重提示：
                //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                //成功关闭页面
                WeixinJSBridge.call('closeWindow');
              }else{
                alert('调起支付失败')
              }
            }
          );
        }
      }
    }
</script>

<style scoped>

</style>
